package com.hejing.面向对象特征之三_多态.初识多态;

/**
 * ClassName: AnimalTest
 * Package: com.hejing.面向对象特征之三_多态.初识多态
 * Description:
 *
 * @Author: HeJing
 * @Create: 2023-03-26 14:45
 * @Version: 1.0
 */
public class AnimalTest {
    public static void main(String[] args) {
        AnimalTest test = new AnimalTest();
        test.adopt(new Cat());
    }

    public void adopt(Animal animal) {
        animal.eat();
        animal.jump();

        // 向下转型:

        if(animal instanceof Dog) {
            Dog dog = (Dog) animal;
            dog.watchDoor();
        } else if(animal instanceof Cat) {
            Cat cat = (Cat)animal;
            cat.catchMouse();
        }


    }
}




















